package cn.tedu.front.details.service.Impl;

import cn.tedu.front.details.dao.cache.ICompanyCacheRepository;
import cn.tedu.front.details.dao.persist.repository.ICompanyRepository;
import cn.tedu.front.details.pojo.vo.CompanyVO;
import cn.tedu.front.details.service.ICompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class CompanyServiceImpl implements ICompanyService {
    @Autowired
    private ICompanyRepository companyRepository;
    @Autowired
    private ICompanyCacheRepository iCompanyCacheRepository;
    @Override
    public void rebuildCache() {
        List<CompanyVO> standard = companyRepository.getStandard();
        for (CompanyVO companyVO : standard) {
            Long id = companyVO.getId();
            iCompanyCacheRepository.saveCompany(id,companyVO);
        }
    }

    @Override
    public CompanyVO getCompanyById(Long id) {
        CompanyVO queryResult = companyRepository.getCompanyById(id);
        if(queryResult==null){
            String message = "查询文章详情失败，文章数据不存在！";
            log.warn(message);
        }
        return queryResult;
    }

    @Override
    public List<CompanyVO> getCompany() {
        //查询所有的CompanyVO集合
        return companyRepository.getStandard();
    }
}
